home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / KSLIB11.ARJ / IFC.DOC < prev    next >
Text File  |  1991-11-12  |  6KB  |  167 lines

  1. Documentation for IFC routines.
  2. -------------------------------
  3. Source file(s)    : ifc.c
  4. Include file(s)    : ifc.h
  5. Library            : tools.lib
  6.  
  7. The routines contained in IFC.C are designed to simplify reading from, and
  8. writing to, the parallel ports in order to use them for simple interfacing
  9. circuits.
  10.  
  11. ===============================================================================
  12.  
  13. Function        int IFCset(int portnum)
  14. Prototype in    ifc.h
  15.  
  16.     Sets the current port to portnum. Portnum can range from 0 to 3, with 0
  17.     being LPT1, and 3 being LPT4.
  18.  
  19. Returns            FALSE if an invalid printer port is specified, TRUE otherwise.
  20.  
  21. -------------------------------------------------------------------------------
  22.  
  23. Function        int16 IFCout(uint8 val)
  24. Prototype in    ifc.h
  25.  
  26.     Outputs the 8 bits of val to the current port.
  27.  
  28. Returns            the value ouput, or -1 if the current port is invalid.
  29.  
  30. -------------------------------------------------------------------------------
  31.  
  32. Function        int16 IFCin()
  33. Prototype in    ifc.h
  34.  
  35.     Reads 8 bits of data from the current port.
  36.  
  37. Returns            the value read, or -1 if the current port is invalid.
  38.  
  39. ===============================================================================
  40.  
  41. General notes :
  42. ---------------
  43.  
  44. Beginning at location 0040:0008 is a block of 8 bytes. These are arranged as
  45. 4 words, 1 for each of the ports LPT1 to LPT4. If this word is 0, the corres-
  46. ponding port is invalid, otherwise the word contains the base I/O address of
  47. the port. Starting from this base addresss are 3 locations of interest.
  48.  
  49. At [base+0] is an 8-bit latch leading to pins 2-9 on the connector. There is
  50. also a tri-state buffer reverse-connected across this latch, so that reading
  51. this address will return the current states of pins 2-9. Unfortunately, that
  52. does not mean these pins can be used for input, as the latch is not open-
  53. collector. However, this feature is useful for verifying that written data has
  54. actually made it to the hardware.
  55.  
  56. At [base+1] is an I/O chip, of which bits 3-7 are useful. This chip can
  57. only be used for inputting data. Bits 3-6 will read as 0 if the appropriate
  58. pin is at GND relative to pin 25, or 1 if the pin is at +5v. However, bit 7
  59. is inverted - It will read 0 if pin 11 is at +5v and 1 if it's at GND.
  60.  
  61. At [base+2] is another chip, of which bits 0-3 can be read or written. This
  62. chip is a set of open-collector output transistors, with tri-state buffers
  63. reverse-connected to enable reading. Bits 0, 1 and 3 are inverted. A 1 in the
  64. bit position will produce GND on the appropriate pin, while a 0 will produce
  65. a floating (+5v) value. Bit 2 will produce +5v if it's 1, or a floating GND
  66. if it's 0.
  67.  
  68. This gives a total of 17 bits which can be played with, as follows :
  69.  
  70. Offset    bit        Pin        Direction
  71. 0        0        2        Output
  72. 0        1        3        Output
  73. 0        2        4        Output
  74. 0        3        5        Output
  75. 0        4        6        Output
  76. 0        5        7        Output
  77. 0        6        8        Output
  78. 0        7        9        Output
  79. 1        3        15        Input
  80. 1        4        13        Input
  81. 1        5        12        Input
  82. 1        6        10        Input
  83. 1        7        11        Input        Inverted
  84. 2        0         1        Either        Inverted
  85. 2        1        14        Either        Inverted
  86. 2        2        16        Either
  87. 2        3        17        Either        Inverted
  88.  
  89. As written, my functions use the first 8 bits (Offset 1, 3-7 and Offset 2, 0-2)
  90. as input pins. This gives us a total of 8 inputs and 8 outputs (from Offset 0).
  91. I figured this was a good balance, and it shouldn't be too hard to write some
  92. routines for any other configuration. Some possibly useful configurations
  93. would be :
  94.  
  95. 12 outputs, 5 inputs,
  96. 8 outputs,  9 inputs, or
  97. 9 outputs,  8 inputs.
  98.  
  99. WARNING : You should be careful not to change any bits in these locations
  100. other than the necessary ones. I can't remember what they do. Also, Bits 0-3
  101. of Offset 2 terminate at open-collector ouputs on the chip. If you're going
  102. to use these for inputs, you need to make sure you don't short them to +5v
  103. while they are latched at Gnd. However, the other way is quite okay. The safest
  104. bet is to only connect up gear which shorts them to ground, or leaves them Open
  105. circuit. They have pullup resistors internal to them, and if left floating will
  106. quite happily show a '1'.This will prevent damage to the chip, then all you
  107. have to remember is to write them correct value to each of these bits before
  108. doing any reading from them. This makes sure the outputs are not S/C to ground
  109. by the chip itself. If this doesn't make sense, the following suggested
  110. connection diagram might help.
  111.  
  112.               PC               |                Your Gear
  113.                                |
  114.               +5v              |
  115.                |               |
  116.                Z resistor      |
  117.                |---------------------- SWITCH
  118.               |/               |         |
  119. Bit 0-3   ----|                |         |
  120.               |\               |        Gnd
  121.                |               |
  122.                |               |
  123.               Gnd              |
  124.                                |
  125.  
  126. Here's the pin to port/bit assignments.
  127.  
  128. Pin        IFCallout    IFCallin    IFCout    IFCin    Port/Bit    Direction
  129. -----------------------------------------------------------------------------
  130.  1           8           0                  0           2/0        Both
  131.  2           0                      0                   0/0        Out
  132.  3           1                      1                   0/1        Out
  133.  4           2                      2                   0/2        Out
  134.  5           3                      3                   0/3        Out
  135.  6           4                      4                   0/4        Out
  136.  7           5                      5                   0/5        Out
  137.  8           6                      6                   0/6        Out
  138.  9           7                      7                   0/7        Out
  139. 10                       7                  6           1/6        In
  140. 11                       8                  7           1/7        In
  141. 12                       6                  5           1/5        In
  142. 13                       5                  4           1/4        In
  143. 14           9           1                  1           2/1        Both
  144. 15                       4                  3           1/3        In
  145. 16          10           2                  2           2/2        Both
  146. 17          11           3                           2/3        Both
  147. -----------------------------------------------------------------------------
  148.  
  149. Here's the normal pin functions for a printer port.
  150.  
  151. Pin        Function at PC                    Pin        Function at PC
  152. -----------------------------------------------------------------------------
  153.  1        Strobe out                        14        Auto LF out
  154.  2        D0 out                            15        Fault in
  155.  3        D1 out                            16        Init out
  156.  4        D2 out                            17        Select out
  157.  5        D3 out                            18        Gnd
  158.  6        D4 out                            19        Gnd
  159.  7        D5 out                            20        Gnd
  160.  8        D6 out                            21        Gnd
  161.  9        D7 out                            22        Gnd
  162. 10        ACK in                            23        Gnd
  163. 11        Busy in                            24        Gnd
  164. 12        Paper End in                    25        Gnd
  165. 13        Select in
  166. -----------------------------------------------------------------------------
  167.